package com.achobeta.recruitment.controller.student;

import com.achobeta.recruitment.common.AppResult;
import com.achobeta.recruitment.common.ResultCode;
import com.achobeta.recruitment.common.Rule;
import com.achobeta.recruitment.model.Manager;
import com.achobeta.recruitment.model.vo.StudentVO;
import com.achobeta.recruitment.service.student.StudentService;
import com.achobeta.recruitment.utils.LimitUtils;
import com.achobeta.recruitment.utils.SessionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-11-06
 * Time: 21:56
 */
@Api(tags = "学生相关")
@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("获取状态表")
    @GetMapping("/states")
    public AppResult<List<String>> getStateList() {
        List<String> stateList = studentService.getStateList();
        return AppResult.success(stateList);
    }


    @ApiOperation("获取学生列表")
    @GetMapping("/list")
    public AppResult<List<StudentVO>> getStudentList(HttpServletRequest request) {
        // 获取当前登录用户
        Manager manager = SessionUtils.getManager(request);
        // 判断是否有权限
        if(!LimitUtils.hasPower(manager, Rule.STUDENT_LIST_RULE)) {
            log.warn(ResultCode.FAILED_MANAGER_NOT_POWERS.toString());
            return AppResult.failed(ResultCode.FAILED_MANAGER_NOT_POWERS);
        }
        List<StudentVO> studentVOS = studentService.getStudentList();
        return AppResult.success(studentVOS);
    }



}
